package com.tianqu.tms.www.cardect.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.StringUtil;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.www.cardect.actionform.TisDetectSeniorActionForm;
import com.tianqu.tms.www.cardect.viewhelper.CarSeniorDetectViewHelper;
/**
 * 
 * 普通检测一、用于图片上传的中转
 * 
 * 页面提交的时候将表单信息放到uc中待调用
 * 
 * @author tianshifu
 *
 */
public class CarWDPersonSeniorDetectPicDispatchAction extends TmsAction {
	private Logger logger = Logger.getLogger(CarWDPersonSeniorDetectPicDispatchAction.class);//log
	private static final String IMGKEY = "imgKey";// 图片位置
	private static final String IMGTYPE = "imgType";// 图片类型
	private static final String CHKMODEL = "chkModel";//检测模式
	private static final String DETECT_POSITION = "detect_position";//检测位置，标识哪个button提交
	private static final String SENIOR_DETECT_INPUT_DATA = "senior_detect_input_data";//检测录入信息
	
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");	
		String actionForward = "";
		TisDetectSeniorActionForm seniorForm = (TisDetectSeniorActionForm)form;
		/***************每个页面图片对应的key值不同,取图片的时候需要在外面加一层图片类型判断******************/
		if(seniorForm.getImageButton1()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "1");
			uc.setAttribute(CHKMODEL, "2");			
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton2()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "2");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton3()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "3");
			uc.setAttribute(CHKMODEL, "2");		
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton4()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "4");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}
		//-------------------------------------
		if(seniorForm.getImageButton5()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "5");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton6()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "6");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton7()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "7");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton8()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "8");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton9()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "9");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton10()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "10");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton11()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "11");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton12()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "12");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton13()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "13");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton14()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "14");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton15()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "15");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton16()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "16");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton17()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "17");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton18()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "18");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton19()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "19");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton20()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "20");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton21()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "21");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton22()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "22");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton23()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "23");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton24()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "24");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton25()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "25");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton26()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "26");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton27()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "27");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton28()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "28");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton29()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "29");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton30()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "30");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton31()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "31");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton32()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "32");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton33()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "33");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}
		if(seniorForm.getImageButton34()!=null)
		{
			uc.setAttribute(IMGTYPE, "2");
			uc.setAttribute(IMGKEY, "34");
			uc.setAttribute(CHKMODEL, "2");	
			actionForward = "imgInput";
		}

		if(seniorForm.getSaveButton()!=null)
		{
			actionForward = "toDetectConfirm";//信息确认页
		} 
		
		//从uc中获取数据参数看是按钮位置 来进行页面跳转判定，并带出相应的值
		//每次都进入到这个Action中 进入到这个页面的时候需要传过来一个位置ID 根据位置ID对对应的选项进行添加
		//每次都需要判断是否为空，为空的话过掉
		//从form中获取页面表单
		TisDetectSeniorActionForm seniorDetectForm = (TisDetectSeniorActionForm)form;		
		
		CarSeniorDetectViewHelper topView = (CarSeniorDetectViewHelper)uc.getAttribute(SENIOR_DETECT_INPUT_DATA);
		
				
		//向viewhelp中set列表list 包括缺陷程度描述和评分 从字典表中取得
		//Codes code = Codes.getInstance();

		String	position = (String)uc.getAttribute(DETECT_POSITION);
		
		//根据位置跳转到不同的页面
		if(position.equals("1"))
		{
			/******** 事故项检查 ************/
			topView.setBodyChk1(transStr(seniorDetectForm.getBodyChk1()));
			topView.setBodyChk2(transStr(seniorDetectForm.getBodyChk2()));
			topView.setBodyChk3(transStr(seniorDetectForm.getBodyChk3()));
			topView.setBodyChk4(transStr(seniorDetectForm.getBodyChk4()));
			topView.setBodyChk5(transStr(seniorDetectForm.getBodyChk5()));
			topView.setBodyChk6(transStr(seniorDetectForm.getBodyChk6()));
			topView.setBodyChk7(transStr(seniorDetectForm.getBodyChk7()));
			topView.setBodyChk8(transStr(seniorDetectForm.getBodyChk8()));
			topView.setBodyChk9(transStr(seniorDetectForm.getBodyChk9()));
			topView.setBodyChk10(transStr(seniorDetectForm.getBodyChk10()));
			topView.setBodyChk11(transStr(seniorDetectForm.getBodyChk11()));
			topView.setBodyChk12(transStr(seniorDetectForm.getBodyChk12()));
			topView.setBodyChk13(transStr(seniorDetectForm.getBodyChk13()));
			/*********事故车，有一项选中则为事故车***********/
			uc.removeAttribute(DETECT_POSITION);
			uc.setAttribute(DETECT_POSITION, "1");
			
		}
		if(position.equals("2"))
		{
			/*********** 技术检测，车身外观检测 ***************/

			topView.setOutwardChk1(getdetectStr(seniorDetectForm.getOutwardChkS1(),seniorDetectForm.getOutwardChkC1()));
			topView.setOutwardChk2(getdetectStr(seniorDetectForm.getOutwardChkS2(),seniorDetectForm.getOutwardChkC2()));
			topView.setOutwardChk3(getdetectStr(seniorDetectForm.getOutwardChkS3(),seniorDetectForm.getOutwardChkC3()));
			topView.setOutwardChk4(getdetectStr(seniorDetectForm.getOutwardChkS4(),seniorDetectForm.getOutwardChkC4()));
			topView.setOutwardChk5(getdetectStr(seniorDetectForm.getOutwardChkS5(),seniorDetectForm.getOutwardChkC5()));
			topView.setOutwardChk6(getdetectStr(seniorDetectForm.getOutwardChkS6(),seniorDetectForm.getOutwardChkC6()));
			topView.setOutwardChk7(getdetectStr(seniorDetectForm.getOutwardChkS7(),seniorDetectForm.getOutwardChkC7()));
			topView.setOutwardChk8(getdetectStr(seniorDetectForm.getOutwardChkS8(),seniorDetectForm.getOutwardChkC8()));
			topView.setOutwardChk9(getdetectStr(seniorDetectForm.getOutwardChkS9(),seniorDetectForm.getOutwardChkC9()));
			topView.setOutwardChk10(getdetectStr(seniorDetectForm.getOutwardChkS10(),seniorDetectForm.getOutwardChkC10()));
			topView.setOutwardChk11(getdetectStr(seniorDetectForm.getOutwardChkS11(),seniorDetectForm.getOutwardChkC11()));
			topView.setOutwardChk12(getdetectStr(seniorDetectForm.getOutwardChkS12(),seniorDetectForm.getOutwardChkC12()));
			topView.setOutwardChk13(getdetectStr(seniorDetectForm.getOutwardChkS13(),seniorDetectForm.getOutwardChkC13()));
			topView.setOutwardChk14(getdetectStr(seniorDetectForm.getOutwardChkS14(),seniorDetectForm.getOutwardChkC14()));
			topView.setOutwardChk15(getdetectStr(seniorDetectForm.getOutwardChkS15(),seniorDetectForm.getOutwardChkC15()));
			topView.setOutwardChk16(getdetectStr(seniorDetectForm.getOutwardChkS16(),seniorDetectForm.getOutwardChkC16()));
			topView.setOutwardChk17(getdetectStr(seniorDetectForm.getOutwardChkS17(),seniorDetectForm.getOutwardChkC17()));
			topView.setOutwardChk18(getdetectStr(seniorDetectForm.getOutwardChkS18(),seniorDetectForm.getOutwardChkC18()));
			topView.setOutwardChk19(getdetectStr(seniorDetectForm.getOutwardChkS19(),seniorDetectForm.getOutwardChkC19()));
			topView.setOutwardChk20(getdetectStr(seniorDetectForm.getOutwardChkS20(),seniorDetectForm.getOutwardChkC20()));
			topView.setOutwardChk21(getdetectStr(seniorDetectForm.getOutwardChkS21(),seniorDetectForm.getOutwardChkC21()));
			topView.setOutwardChk22(getdetectStr(seniorDetectForm.getOutwardChkS22(),seniorDetectForm.getOutwardChkC22()));
			topView.setOutwardChk23(getdetectStr(seniorDetectForm.getOutwardChkS23(),seniorDetectForm.getOutwardChkC23()));
			topView.setOutwardChk24(getdetectStr(seniorDetectForm.getOutwardChkS24(),seniorDetectForm.getOutwardChkC24()));
			topView.setOutwardChk25(getdetectStr(seniorDetectForm.getOutwardChkS25(),seniorDetectForm.getOutwardChkC25()));
			topView.setOutwardChk26(seniorDetectForm.getOutwardChkC26());	//轮胎只有一个程度,没有缺陷描述		
		
			uc.removeAttribute(DETECT_POSITION);
			uc.setAttribute(DETECT_POSITION, "2");
		}
		if(position.equals("3"))
		{
			/*********** 技术检测，发动机舱检测 ***************/
			
			topView.setEngineChk1(seniorDetectForm.getEngineChk1());
			topView.setEngineChk2(seniorDetectForm.getEngineChk2());
			topView.setEngineChk3(seniorDetectForm.getEngineChk3());
			topView.setEngineChk4(seniorDetectForm.getEngineChk4());
			topView.setEngineChk5(seniorDetectForm.getEngineChk5());
			topView.setEngineChk6(seniorDetectForm.getEngineChk6());
			topView.setEngineChk7(seniorDetectForm.getEngineChk7());
			topView.setEngineChk8(seniorDetectForm.getEngineChk8());
			topView.setEngineChk9(seniorDetectForm.getEngineChk9());

			uc.removeAttribute(DETECT_POSITION);
			uc.setAttribute(DETECT_POSITION, "3");
		}
		if(position.equals("4"))
		{
			/*********** 技术检测，驾驶舱检测 ***************/
			
			topView.setPilotChk1(seniorDetectForm.getPilotChk1());
			topView.setPilotChk2(seniorDetectForm.getPilotChk2());
			topView.setPilotChk3(seniorDetectForm.getPilotChk3());
			topView.setPilotChk4(seniorDetectForm.getPilotChk4());
			topView.setPilotChk5(seniorDetectForm.getPilotChk5());
			topView.setPilotChk6(seniorDetectForm.getPilotChk6());
			topView.setPilotChk7(seniorDetectForm.getPilotChk7());
			topView.setPilotChk8(seniorDetectForm.getPilotChk8());
			topView.setPilotChk9(seniorDetectForm.getPilotChk9());
			topView.setPilotChk10(seniorDetectForm.getPilotChk10());
			topView.setPilotChk11(seniorDetectForm.getPilotChk11());
			topView.setPilotChk12(seniorDetectForm.getPilotChk12());
			topView.setPilotChk13(seniorDetectForm.getPilotChk13());
			topView.setPilotChk14(seniorDetectForm.getPilotChk14());

			uc.removeAttribute(DETECT_POSITION);
			uc.setAttribute(DETECT_POSITION, "4");
		}
		if(position.equals("5"))
		{
			/*********** 技术检测，启动检测 ***************/
	
			topView.setStartChk1(seniorDetectForm.getStartChk1());
			topView.setStartChk2(seniorDetectForm.getStartChk2());
			topView.setStartChk3(seniorDetectForm.getStartChk3());
			topView.setStartChk4(seniorDetectForm.getStartChk4());
			topView.setStartChk5(seniorDetectForm.getStartChk5());
			topView.setStartChk6(seniorDetectForm.getStartChk6());
			topView.setStartChk7(seniorDetectForm.getStartChk7());
			topView.setStartChk8(seniorDetectForm.getStartChk8());
			topView.setStartChk9(seniorDetectForm.getStartChk9());
			
			uc.removeAttribute(DETECT_POSITION);
			uc.setAttribute(DETECT_POSITION, "5");
		}
		if(position.equals("6"))
		{
			/*********** 技术检测，路试检测 ***************/
			topView.setRunChk1(seniorDetectForm.getRunChk1());
			topView.setRunChk2(seniorDetectForm.getRunChk2());
			topView.setRunChk3(seniorDetectForm.getRunChk3());
			topView.setRunChk4(seniorDetectForm.getRunChk4());
			topView.setRunChk5(seniorDetectForm.getRunChk5());
			topView.setRunChk6(seniorDetectForm.getRunChk6());
			topView.setRunChk7(seniorDetectForm.getRunChk7());
			topView.setRunChk8(seniorDetectForm.getRunChk8());
			topView.setRunChk9(seniorDetectForm.getRunChk9());
	
			uc.removeAttribute(DETECT_POSITION);
			uc.setAttribute(DETECT_POSITION, "6");
		}
		if(position.equals("7"))
		{
			/*********** 技术检测，底盘检测 ***************/
	
			topView.setBottomChk1(seniorDetectForm.getBottomChk1());
			topView.setBottomChk2(seniorDetectForm.getBottomChk2());
			topView.setBottomChk3(seniorDetectForm.getBottomChk3());
			topView.setBottomChk4(seniorDetectForm.getBottomChk4());
			topView.setBottomChk5(seniorDetectForm.getBottomChk5());
			topView.setBottomChk6(seniorDetectForm.getBottomChk6());
			topView.setBottomChk7(seniorDetectForm.getBottomChk7());


			uc.removeAttribute(DETECT_POSITION);
			uc.setAttribute(DETECT_POSITION, "7");
		}
		if(position.equals("8"))
		{
			//八、检测说明录入
			topView.setCarDescribe(seniorDetectForm.getCarDescribe());
			uc.removeAttribute(DETECT_POSITION);
			uc.setAttribute(DETECT_POSITION, "8");
		}
		
		request.setAttribute(TmsConstants.VIEWHELP, topView);
		uc.setAttribute(SENIOR_DETECT_INPUT_DATA, topView);//将检测信息set到uc中带进入首页时查看
		
		logger.debug(this.getClass().getName() + "#doAction was completed.");
		return mapping.findForward(actionForward);
	}
	
	private String transStr(String str)
	{
		if("".equals(str)||str == null)
		{
			return "-";
		}
		
		return str;
	}
	
	/**
	 * 
	 * 合并字符串，放到首页检测报告录入中
	 */
	private String getdetectStr(String decName,String decLevel)
	{
		String str = "-";
		if(!"".equals(StringUtil.isNULL(decName))&&!"".equals(StringUtil.isNULL(decLevel)))
		{
			//如果都不为空,缺陷+程度
			return (decName+decLevel);
		}
		if("".equals(StringUtil.isNULL(decName))&& "".equals(StringUtil.isNULL(decLevel)))
		{
			//同时为空，则返回"-"
			return str;
		}
		if(!"".equals(StringUtil.isNULL(decName)))
		{
			//如果缺陷名字不为空，则返回缺陷名
			return decName;
		}
		return str;
	}
}
